package com.example.yinhangmiaosha.config;

import com.example.yinhangmiaosha.interceptor.LimitInterceptor;
import com.example.yinhangmiaosha.interceptor.TimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    TimeInterceptor timeInterceptor;

    @Autowired
    LimitInterceptor limitInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = null;
        registration = registry.addInterceptor(timeInterceptor);
        registration.addPathPatterns("/**");    // 拦截路径
        registration.excludePathPatterns(           //添加不拦截路径
                "/css/**",            //css静态资源
                "/js/**",              //js静态资源
                "/img/**",             //img静态资源
                "/login.html",
                "/index.html",
                "/userLogin",
                "/error",
                "/nopermission"
        );

        registration = registry.addInterceptor(limitInterceptor);
        registration.addPathPatterns("/**");    // 拦截路径
        registration.excludePathPatterns(           //添加不拦截路径
                "/css/**",            //css静态资源
                "/js/**",              //js静态资源
                "/img/**",             //img静态资源
                "/login.html",
                "/index.html",
                "/userLogin",
                "/error",
                "/nopermission"
        );
    }

}
